
import 'dart:convert';

import 'package:du_application/main.dart';
import 'package:du_application/model/OrderModel.dart';
import 'package:du_application/pages/ListPage.dart';
import 'package:du_application/pages/affiar/AffairDetail.dart';
import 'package:du_application/pages/affiar/AffairList.dart';
import 'package:du_application/pages/buy/submit.dart';
import 'package:du_application/pages/camera/CameraPage.dart';
import 'package:du_application/pages/camera/affairs.dart';
import 'package:du_application/pages/camera/image.dart';
import 'package:du_application/pages/classify/classify.dart';
import 'package:du_application/pages/collect/CollectPage.dart';

import 'package:du_application/pages/detail/GoodsDetails.dart';
import 'package:du_application/pages/evaluate/evaluate.dart';
import 'package:du_application/pages/login/login.dart';
import 'package:du_application/pages/login/registerCode.dart';
import 'package:du_application/pages/order/order.dart';
import 'package:du_application/pages/person_center/PersonalCenter.dart';
import 'package:du_application/pages/person_center/UserInfoPage.dart';
import 'package:du_application/provide/AffairDetailProvider.dart';
import 'package:du_application/provide/AffairListProvider.dart';
import 'package:du_application/provide/AuthProvider.dart';
import 'package:du_application/provide/ClassifyProvider.dart';
import 'package:du_application/provide/GoodsProvider.dart';
import 'package:du_application/provide/InfoProvider.dart';
import 'package:du_application/provide/ListProvider.dart';
import 'package:du_application/provide/person.dart';
import 'package:flutter/material.dart';
import 'package:fluro/fluro.dart';
import 'package:provide/provide.dart';

Handler rootHanderler =Handler(
  handlerFunc: (BuildContext context,Map<String,List<String>> params){

    return MyApp();
  }

);
Handler affairDetailHanderler =Handler(
  handlerFunc: (BuildContext context,Map<String,List<String>> params){
       String id = params['id'].first;
     Provide.value<AffairDetailProvider>(context).getAffair(context,id);
    return AffairDetail();
  }

);
Handler noLoginHanderler=Handler(
  handlerFunc: (BuildContext context,Map<String,List<String>> params){
    return Login();
  });
Handler personHanderler =Handler(
  handlerFunc: (BuildContext context,Map<String,List<String>> params){
    if(Provide.value<AuthProvider>(context).token==null){
      return Login();
    }else{
       Provide.value<PersonProvide>(context).getUserInfo(context);
  return PersonCeter();
    }
   
   
  });
Handler goodsHanderler =Handler(
  handlerFunc: (BuildContext context,Map<String,List<String>> params){
    String goodsId = params['id'].first;
     Provide.value<GoodsProvider>(context).getGoods(goodsId);
   
    return GoodsDetails();
  });
Handler loginHanderler=Handler(
  handlerFunc: (BuildContext context,Map<String,List<String>> params){
     return Login(); 
  });
// Handler cameraHanderler=Handler(
//   handlerFunc: (BuildContext context,Map<String,List<String>> params){

//     return CameraPage();
//   });
Handler imageHanderler=Handler(
  handlerFunc: (BuildContext context,Map<String,List<String>> params){

    return ImagePickerWidget();
  });
Handler registerHanderler=Handler(
  handlerFunc: (BuildContext context,Map<String,List<String>> params){

    return RegFormCode();
  });
Handler affairsHanderler=Handler(
  handlerFunc: (BuildContext context,Map<String,List<String>> params){

    return Affairs();
  });
Handler collectHanderler=Handler(
  handlerFunc: (BuildContext context,Map<String,List<String>> params){

    return CollectPage();
  });
Handler classifyHanderler=Handler(
  handlerFunc: (BuildContext context,Map<String,List<String>> params){
         Provide.value<ClassProvider>(context).getCategory();
    return ClassifyPage();
  });
Handler orderHanderler=Handler(
  handlerFunc: (BuildContext context,Map<String,List<String>> params){
 
    return Order();
  });
Handler evaluateHanderler=Handler(
  handlerFunc: (BuildContext context,Map<String,List<String>> params){
 
   int id = int.parse(params['id'].first);
    return Evaluate(id:id);
  });

Handler listHanderler=Handler(
  handlerFunc: (BuildContext context,Map<String,List<String>> params){
     if(params['id']!=null){
      String id = params['id'].first;
     Provide.value<ListProvider>(context).getList(id:id);
     return ListPage(id:id,);
     }
     else{
       String keyword = params['keyword'].first;
         Provide.value<ListProvider>(context).getList(keyword:keyword);
         return ListPage(keyword:keyword,);
     }
        
   
  });
Handler infoHanderler=Handler(
  handlerFunc: (BuildContext context,Map<String,List<String>> params){

    Provide.value<InfoProvider>(context).getInfo();
        // String id = params['id'].first;
    // Provide.value<ListProvider>(context).getList(id);
    return UserInfoPage();
  });
Handler submitHanderler=Handler(
  handlerFunc: (BuildContext context,Map<String,List<String>> params){

    // Provide.value<InfoProvider>(context).getInfo();
    String order = params['order'].first;
    OrderModel orderModel=OrderModel.fromJson(json.decode(order));
    // Provide.value<ListProvider>(context).getList(id);
    return OrderSubmit(orderModel:orderModel);
  });
Handler affairListHanderler=Handler(
  handlerFunc: (BuildContext context,Map<String,List<String>> params){
    Provide.value<AffairListProvider>(context).getAffair(context,1,6);
    // // Provide.value<InfoProvider>(context).getInfo();
    // String order = params['order'].first;
    // OrderModel orderModel=OrderModel.fromJson(json.decode(order));
    // Provide.value<ListProvider>(context).getList(id);
    return AffairList();
  });